import time
from datetime import datetime
class Date():
    @staticmethod
    def microtime():
        """
        获取当前带小数的时间戳
        @return:
        """
        return time.time()

    @staticmethod
    def time():
        """
        获取当前整数的时间戳
        @return:
        """
        return int(time.time())

    @staticmethod
    def date(format = "%Y-%m-%d %H:%M:%S", timestamp = None):
        """
        格式化 Unix 时间戳
        @param format:
        @param timestamp:
        @return:
        """
        if(timestamp != None):
            object = datetime.datetime.fromtimestamp(timestamp)
        else:
            object = datetime.now()

        return object.strftime(format)

    @staticmethod
    def strtotime(timeStr, format = "%Y-%m-%d %H:%M:%S"):
        """
        字符串日期转时间戳
        @param timeStr:
        @param format:
        @return:
        """
        #如 2025-04-17 12:34:56, %Y-%m-%d %H:%M:%S
        time_obj = datetime.strptime(timeStr, format)

        # 使用timestamp方法将datetime对象转换为时间戳
        return int(time_obj.timestamp())
